// pages/merchantDetails/index.js
const app = getApp()
Page({
  data: {
    merchantsInfo: {
      src: ''
    },
    code: '',
    merchanrBaseInfo: {
      addressName: '',
      categoryName: '',
      code: '453456574567486758',
      contactsEmaill: '8978394@qq.com',
      contactsName: '望天',
      customerServiceNumber: 13589877890,
      detailedAddress: '',
      mobile: 13589877890,
      name: '南国宇文店'
    },
    baseInfo: [{
      title: '上游商户号',
      value: '453456574567486758'
    }],
    settlement: [{
        title: '到帐银行卡',
        value: '6214987667898876'
      },
      {
        title: '结算方式',
        value: 'T+1'
      }
    ],
    merchantSettlementInfo: {
      bankAccountCode: '',
      bankAddress: '招商银行武汉支行',
      bankPhoneNum: 13589877890,
      billingType: 0,
      code: '',
      name: '',
      settlementPersonCardCode: '421087909876567874',
      settlementPersonName: '王珊'
    },
    merchantPayInfoVo: {
      code: '',
      name: '',
      vxPayInfo: {
        payProportion: '千分之3',
        payTypeName: '微信支付'
      },
      ysfPayInfo: {
        payProportion: '千分之3',
        payTypeName: '银联云闪付'
      },
      zfbPayInfo: {
        payProportion: '千分之3',
        payTypeName: '支付宝'
      }
    }
  },
  toBaseInfoPage(e) {
    console.log(e)
    const {
      merchanrBaseInfo
    } = this.data
    // pages/baseInfo/index
    wx.navigateTo({
      url: '/pages/baseInfo/index',
      success: function (res) {
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          merchanrBaseInfo
        })
      }
    })
  },
  toSettlementPage(e) {
    const {
      settlement
    } = this.data
    // pages/baseInfo/index
    wx.navigateTo({
      url: '/pages/settlement/index',
      success: function (res) {
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          settlement
        })
      }
    })
  },
  goTerminalManage(e) {
    const {
      settlement
    } = this.data
    wx.navigateTo({
      url: '/pages/terminalManage/index',
      success: function (res) {
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          settlement
        })
      }
    })
  },
  goShopManage(e) {
    const {
      settlement
    } = this.data
    wx.navigateTo({
      url: '/pages/shopManage/index',
      success: function (res) {
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          settlement
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  goSetting(e) {
    var that = this
    wx.navigateTo({
      url: '/pages/merchantDetails/setting/index',
      success: function (res) {
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          code: that.data.code
        })
      }
    })
  },
  onLoad: function (option) {
    const eventChannel = this.getOpenerEventChannel()
    // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
    var that = this
    // wx.showLoading({
    //   title: '加载中',
    // })
    eventChannel.on('acceptDataFromOpenerPage', function (data) {
      app.ajax.requestPost(app.api.getMerchantInfo, {
        code: data.code
      }).then((res) => {
        console.log(res)
        wx.hideLoading()
        that.setData({
          merchanrBaseInfo: res.data.merchanrBaseInfo,
          // merchantPayInfoVo:res.data.merchantPayInfoVo,
          merchantSettlementInfo: res.data.merchantSettlementInfo,
          code:data.code
        })
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {}
})